<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta
      http-equiv="Cache-control"
      content="no-cache,no-store,must-revalidate"
    />
    <meta http-equiv="Cache" content="no-cache" />
    <title>编辑页面</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
  </head>
  <body>
    <form class="layui-form" action="" lay-filter="form-filter">
      <div class="mainBox">
        <div class="main-container">
          <div class="layui-form-item">
            <label class="layui-form-label">制造部名称</label>
            <div class="layui-input-block">
              <input
                type="text"
                name="topDeptName"
                lay-verify="required"
                autocomplete="off"
                placeholder="请输入制造部名"
                class="layui-input"
              />
            </div>
          </div>
        </div>
      </div>
      <div class="bottom">
        <div class="button-container">
          <button
            type="submit"
            class="pear-btn pear-btn-primary pear-btn-sm"
            lay-submit=""
            lay-filter="topDeptEdit"
          >
            <i class="layui-icon layui-icon-ok"></i>
            提交
          </button>
        </div>
      </div>
    </form>
    <script src="../../../component/layui/layui.js"></script>
    <script src="../../../component/pear/pear.js"></script>

    <script>
      // 加载自定义模块,检查浏览器和token
      layui.extend({
        myheader: "{/}/lay-ext/myheader",
      });

      layui.use(["form", "jquery", "myheader", "layer"], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let myheader = layui.myheader;
        let layer = layui.layer;

        var optionData = {
          fuData: {},
        };

        // 定义全局 ajax的请求头
        myheader.ajaxGlobal(myheader.checkToken().tokenValue);

        // 获取父页的数据
        optionData.fuData = layui.sessionData("fu2zi").fuData;

				// 清空父传子时临时用的session对象
        layui.sessionData("fu2zi", null);

				// 填充其他默认值
        form.val("form-filter", {
          topDeptName: optionData.fuData.topDeptName,
        });

        form.on("submit(topDeptEdit)", function (data) {

          $.ajax({
            url: parent.layui.myheader.baseUrl() + "/topDept/uptTopDept",
            data: JSON.stringify({
							departmentID: optionData.fuData.topDeptID,
              departmentName: data.field.topDeptName
            }),
            contentType: "application/json", // 请求时的数据类型
            // dataType: 'json',										// 响应的数据类型
            type: "post",
            success: function (data) {
              if (data.data == 1) {
                layer.msg(
                  "已更新",
                  {
                    time: 1000,
                  },
                  function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                    parent.layui.table.reloadData("topdept-table", {
                      scrollPos: "fixed", // 保持滚动条位置不变 - v2.7.3 新增
                    });
                  }
                );
              } else {
                layer.msg("更新失败,原因:" + data.msg, {
                  time: 1500,
                });
              }
            },
          });
          return false;
        });
      });
    </script>
    <script></script>
  </body>
</html>
